package ruleta_wicket.ruleta_wicket;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.time.Duration;
import org.odlabs.wiquery.ui.button.ButtonBehavior;

import ar.edu.unq.auxiliar.domain.Sub1Page;
import domain.Player;

public class LogginPage extends WebPage {

	private static final long serialVersionUID = 1L;

	private Player player;
	
	private int count = 0;
	
	public LogginPage(final PageParameters parameters) {
		Form<Player> form = new Form<Player>("logginForm", this.createModel());
		this.add(form);

		this.addFields(form);
		this.addActions(form);
		
		
		form.add(new Link("unejemplo") {
			@Override
			public void onClick() {
				this.setResponsePage(Sub1Page.class);
			}
		});
		
	}

	@SuppressWarnings("serial")
	private void addActions(final Form<Player> form) {
		Button entrar = new Button("entrar") {
			@Override
			public void onSubmit() {
				LogginPage.this.player.joinTheTable( WicketApplication.getApplication().getTable());
				this.setResponsePage(new TablePage(player));
			}
		};
		
		entrar.add(new ButtonBehavior());
		form.add(entrar);

		form.add(new Link("linkVolver") {
			@Override
			public void onClick() {
				this.setResponsePage(HomePage.class);
			}
		});
	}

	private void addFields(Form<Player> form) {
		form.add(new TextField<Player>("nombre", new PropertyModel<Player>(this.player, Player.NAME)));
		form.add(new TextField<Player>("dinero", new PropertyModel<Player>(this.player, Player.MONEY)));
		form.add(new FeedbackPanel("feedbackPanel"));
	}

	protected CompoundPropertyModel<Player> createModel() {
		this.player= new Player(); 
		return new CompoundPropertyModel<Player>(this.player);
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getCount() {
		return count;
	}
}
